﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;

namespace Intel.Model
{
    public   class SQLXmlReader
    {
        public SQLXmlReader(string XMLPath)
        {
            try
            {
                XDoc = XDocument.Load(XMLPath);
            }
            catch (System.Exception ex)
            {
                XDoc = new XDocument(
                    new XDeclaration("1.0", "utf-8", "yes"),
                    new XComment("Last24Data Command Xml"),
                    new XElement("Last24Data", "select strftime('%H:00:00',timestamp) as Time,count(1) as 'Op Nums' from keyrecords group by strftime('%H',timestamp)")
                    );
                XDoc.Save(XMLPath);
            }
        }
        public string this[string QueryName]
        {
            get
            {
                var Cmds = from ele in XDoc.Elements()
                           where ele.Name == QueryName
                           select ele.Value;
                if (Cmds.Count() > 0)
                {
                    return Cmds.ElementAt(0);
                }
                return null;
                
            }
        }
        public System.Collections.Generic.IEnumerable<string> Cmds
        {
            get
            {
                var Cmds = from ele in XDoc.Elements()

                           select ele.Value;
                return Cmds;
            }
        }
        private XDocument XDoc;
    }
}
